﻿#region zh-CHS 2006 - 2010 DemoSoft 团队 | en 2006-2010 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2010 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Diagnostics;
using Demo.Mmose.Core.Common.SafeCollections;
using Demo.Mmose.Core.Common;
using System.Collections.Generic;
using Demo.Mmose.Core.Entity.Creature;
using Demo.Mmose.Core.Entity.GameObject;
#endregion

namespace Demo.Mmose.Core.Entity.Suit.Quest
{
    /// <summary>
    /// 
    /// </summary>
    public class QuestHandlers
    {

        #region zh-CHS 共有属性 | en Public Properties
        /// <summary>
        /// 
        /// </summary>
        public int Count
        {
            get { return m_QuestActionHandlers.Count; }
        }
        #endregion

        #region zh-CHS 公开方法 | en Public Method

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Dictionary<long, IQuestHandler> m_QuestActionHandlers = new Dictionary<long, IQuestHandler>();
        #endregion
        /// <summary>
        /// 注册数据包的处理调用者
        /// </summary>
        /// <param name="iPacketID"></param>
        /// <param name="iLength"></param>
        /// <param name="bInGame"></param>
        /// <param name="onPacketReceive"></param>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的任务实现调用,不支持多线程操作:警告!" )]
        public void Register( long questId, IQuestHandler questHandler )
        {
            if ( questHandler == null )
                throw new Exception( "QuestHandlers.Register(...) - questHandler == null error!" );

            m_QuestActionHandlers.Add( questId, questHandler );
        }

        /// <summary>
        /// 获取数据包的处理调用者
        /// </summary>
        /// <param name="iPacketID"></param>
        /// <returns></returns>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的任务实现调用,不支持多线程操作:警告!" )]
        public IQuestHandler GetHandler( long questId )
        {
            IQuestHandler questHandler = null;
            m_QuestActionHandlers.TryGetValue( questId, out questHandler );

            return questHandler;
        }

        /// <summary>
        /// 移去数据包的处理调用者
        /// </summary>
        /// <param name="iPacketID"></param>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的任务实现调用,不支持多线程操作:警告!" )]
        public Quest CreateInstance( long questId, object arg )
        {
            IQuestHandler questHandler = null;
            m_QuestActionHandlers.TryGetValue( questId, out questHandler );

            if ( questHandler != null )
                return questHandler.CreateQuest( arg );
            else
                return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="auraId"></param>
        /// <returns></returns>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的任务实现调用,不支持多线程操作:警告!" )]
        public QuestT CreateInstance<QuestT>( long questId, object arg ) where QuestT : Quest
        {
            IQuestHandler questHandler = null;
            m_QuestActionHandlers.TryGetValue( questId, out questHandler );

            if ( questHandler != null )
                return questHandler.CreateQuest( arg ) as QuestT;
            else
                return null;
        }

        #endregion

    }
}
#endregion